package com.example.estest.util;

import io.krakens.grok.api.Grok;
import io.krakens.grok.api.GrokCompiler;
import io.krakens.grok.api.Match;

import java.util.HashMap;
import java.util.Map;

public class GrokUtils {

    public static final GrokCompiler compiler = GrokCompiler.newInstance();
    public static Grok grok = null;

    public static Map<String, Object> toMap(String pattern, String message){
        compiler.registerPatternFromClasspath("/patterns.properties");
        grok = compiler.compile(pattern);
        if(grok!=null){
            Match match = grok.match(message);
            return match.capture();
        } else {
            return new HashMap();
        }
    }
}
